package cn.minsh.lims.eoms.modules.app.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@RestController
@Api(tags = "mq")
public class SendMsgController {

    /**注入RabbitMQ的模板**/
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${spring.rabbitmq.item_topic_exchange}")
    public  String item_topic_exchange ;
    /**
     * 测试
     */
    @GetMapping("/sendMsg")
    @ApiOperation("发送消息")
    public String sendMsg(@RequestParam String msg, @RequestParam String key){
        /**
         * 发送消息
         * 参数一：交换机名称
         * 参数二：路由key: item.springboot-rabbitmq,符合路由item.#规则即可
         * 参数三：发送的消息
         */
        rabbitTemplate.convertAndSend(item_topic_exchange ,key ,msg);
        //返回消息
        return "发送消息成功！";
    }
}
